$(function () {
    var project_id = $('#project_id').val();
    //var init_url = $('#init_url').val();
    var fontString = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二', '十三', '十四', '十五', '十六', '十七', '十八', '十九', '二十'],
        managementStatus = ['','存续','吊销','注销','破产'],
        stakeholder_url = $('#stakeholder_url').val(),
        stakeholder_info_url = $('#stakeholder_info_url').val(),
        stakeholder_add_url = $('#stakeholder_add_url').val(),
        stakeholder_lock_url = $('#investigation_stakeholder_lock_url').val(),
        deleteObj;

    /*---------------------------  保证人及资产情况、抵押人及抵押物情况、其他承债人及资产情况 添加人员  ----------------------------*/
    //点击table中的添加按钮
    $('.nav-tabs').on('click', 'img', function () {
        var name = '',
            number = '',
            stakeholder_type = 0,
            obj = $(this);
        //[1 => '债务人', 2 => '抵押人', 3 => '保证人', 4 => '其他承债人'],

        var length = $(this).parent().parent().parent().find('li').length - 1;
        var i = length;
        i++;
        number = fontString[length] || i;

        if ($(this).parent().parent().parent().is('.di-ya')) {
            name = '抵押人'
            stakeholder_type = 2
        } else if ($(this).parent().parent().parent().is('.baoZheng')) {
            name = '保证人'
            stakeholder_type = 3
        } else if ($(this).parent().parent().parent().is('.chengZhai')) {
            name = '承债人'
            stakeholder_type = 4
        }
        
        /*** start ***/
        /*name += number;
         var str = '<li>' +
         //'<a href="#btab3" data-toggle="tab" data-id="">' +
         '<a href="javascript:;" data-toggle="tab" data-id="" style="width:120px;">' +
         name +
         '<span id="clos" title="点击删除">X</span>' +
         '</a>' +
         '</li>';

         $(this).parent().parent().before(str)*/

        $.ajax({
            type: "POST",
            url: stakeholder_add_url,
            data: {stakeholder_type:stakeholder_type, project_id:project_id},
            datatype: "json",
            success: function (data) {
                if (data.code == 200) {
                    //layer.msg(data.message);
                    name += number;
                    var str = '<li>' +
                        //'<a href="#btab3" data-toggle="tab" data-id="">' +
                        '<a href="javascript:;" data-toggle="tab" data-id="' + data.data.res.id + '" style="width:120px;">' +
                        name +
                        '<span id="clos" title="点击删除">X</span>' +
                        '</a>' +
                        '</li>';

                    obj.parent().parent().before(str)

                    switch (stakeholder_type) {
                        case 2:
                            var ids_arr = $('#stakeholder_pledger_ids').val().split(',');
                            $.each(ids_arr, function (i, n) {
                                if (n == '') {
                                    ids_arr.splice($.inArray('', ids_arr), 1);
                                }
                            });
                            ids_arr.push(data.data.res.id);
                            $('#stakeholder_pledger_count').val(ids_arr.length);
                            $('#stakeholder_pledger_ids').val(ids_arr.join(','));
                            break;
                        case 3:
                            var ids_arr = $('#stakeholder_warrantor_ids').val().split(',');
                            $.each(ids_arr, function (i, n) {
                                if (n == '') {
                                    ids_arr.splice($.inArray('', ids_arr), 1);
                                }
                            });
                            ids_arr.push(data.data.res.id);
                            $('#stakeholder_warrantor_count').val(ids_arr.length);
                            $('#stakeholder_warrantor_ids').val(ids_arr.join(','));
                            break;
                        case 4:
                            var ids_arr = $('#stakeholder_other_ids').val().split(',');
                            $.each(ids_arr, function (i, n) {
                                if (n == '') {
                                    ids_arr.splice($.inArray('', ids_arr), 1);
                                }
                            });
                            ids_arr.push(data.data.res.id);
                            $('#stakeholder_other_count').val(ids_arr.length);
                            $('#stakeholder_other_ids').val(ids_arr.join(','));
                            break;
                        default:
                    }

                } else if (data.code == 400) {
                    layer.msg(data.message);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('系统错误');
            }
        });
        /*** end ***/

        return false;
    })

    //模态框确认
    $('.project_investigation').on('click','.investigation_modal_delete',function(){
        var url = $('.project_investigation').find('.model_url').val(),
            id = $('.project_investigation').find('.model_id').val(),
            project_id = $('#project_id').val(), //项目id
            type = $('.project_investigation').find('.model_type').val();

        if (id != '') {
            $.ajax({
                type: "POST",
                url: url,
                data: {id:id, project_id:project_id},
                datatype: "json",
                success: function (data) {
                    if (data.code == 200) {
                        layer.msg(data.message);
                        if (type == 2) {//文件
                            deleteObj.parent().parent().parent().remove();
                        } else if(type ==1 ){//涉诉
                            deleteObj.parent().parent().remove();
                        }
                    } else if (data.code == 400) {
                        layer.msg(data.message);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('系统错误');
                }
            });
        } else {
            layer.msg('删除成功');
            if (type == 2) {//文件
                deleteObj.parent().parent().parent().remove();
            } else if(type ==1 ){//涉诉
                deleteObj.parent().parent().remove();
            }
        }
    })

    //删除文件
    $('#fuJian').find('.file_list').on('click', '.delete_file', function () {
        deleteObj = $(this);
        $('.project_investigation').find('.model_url').val($(this).data('url'));
        $('.project_investigation').find('.model_id').val($(this).data('id'));
        $('.project_investigation').find('.model_type').val(2);
        $("#rouse_modal").trigger("click");
    })

    //删除涉诉情况
    $(document).on('click','.delete_investigation_lawsuit',function () {
        deleteObj = $(this);
        $('.project_investigation').find('.model_url').val($('#lawsuit_delete_url').val());
        $('.project_investigation').find('.model_id').val($(this).data('id'));
        $('.project_investigation').find('.model_type').val(1);
        $("#rouse_modal").trigger("click");
    })

    //添加涉诉情况
    $('.continueAdd').on('click', function () {
        var length = $(this).parent().parent().prev().find('tr').length - 1;
        var str = '<tr>' +
            '<td>' +
            '	 <input type="text" name="info[' + length + '][records_number]" class="records_number' + length + '" value=""/>' +
            '</td>' +
            '<td>' +
            '	 <input type="text" name="info[' + length + '][accuser]" class="accuser' + length + '" value=""/>' +
            '</td>' +
            '<td>' +
            '	 <input type="text" name="info[' + length + '][defendant]" class="defendant' + length + '" value=""/>' +
            '</td>' +
            '<td>' +
            '	 <input type="text" name="info[' + length + '][money]" class="money' + length + '" value=""/>' +
            '</td>' +
            '<td>' +
            '	 <input type="text" name="info[' + length + '][court]" class="court' + length + '" value=""/>' +
            '</td>' +
            '<td>' +
            '	 <input type="text" name="info[' + length + '][lawsuit_content]" class="lawsuit_content' + length + '" value=""/>' +
            '</td>' +
            '<td>' +
            '<input type="hidden" name="info[' + length + '][id]" id="lawsuit_id' + length + '" value=""/>' +
            //'<input type="button" class="remove delete_investigation_lawsuit" data-id="info[' + length + '][id]" data-toggle="modal" data-target="#deleModal" value="删除" />' +
            '<input type="button" class="remove delete_investigation_lawsuit" data-id="" value="删除" />' +
            '</td>' +
            '</tr>';

        $(this).parent().parent().prev().append(str)
    })

    /*----------------------------------------------------  债权基本情况  ----------------------------------------------------------*/
    var investigation_url = $('#investigation_url').val();

    /*** step1 ***/
    //抵押物类型赋值
    var mortage_type = $('#investigation_mortage_type').val();
    if ($.trim(mortage_type).length > 0) {
        $("#select1").val(mortage_type.split(',')).trigger('change');
    }
    //单击取消
    $('.cancelInConfirm').on('click', '.investigation_step1_cancel', function () {
        var id =　$('#investigation_id1').val(),
            lock_url = $('#investigation_lock_url').val(),
            obj = $(this);
        $.ajax({
            type: "POST",
            url: lock_url,
            data: {id: id, project_id: project_id, type: 2},
            datatype: "json",
            success: function (data) {
                if (data.code == 200) {
                    obj.parent().parent().hide().prev().show().prev().find('img').show();
                    $('.project_edit_state').val(1);
                } else if (data.code == 400) {
                    //layer.msg(data.message);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('系统错误');
            }
        })
    })
    //单击确定
    $('.cancelInConfirm').on('click', '.investigation_step1_confirm', function () {
        //取text
        //var strtext = $('#select1').select2('data').text;
        var strvalue = $("#select1").select2("val");
        $('#investigation_mortage_type').val(strvalue);
        var param = $("form[name='investigation_step1']").serialize();
        investigation(investigation_url, param, $(this), 1);
    });

    /*** step2 司法进展***/
    //单击取消
    $('.cancelInConfirm').on('click', '.investigation_step2_cancel', function () {
        var id = $('#investigation_id1').val(),
            url = $('#cancel_investigation_url').val();
        cancel_investigation(url, {id: id}, $(this));
    })
    //单击确定
    $('.cancelInConfirm').on('click', '.investigation_step2_confirm', function () {
        var param = $("form[name='investigation_step2']").serialize();
        investigation(investigation_url, param, $(this), 1);
    });

    /*** step3  本案诉情况***/
    //单击取消
    $('.cancelInConfirm').on('click', '.investigation_step3_cancel', function () {
        var id = $('#investigation_id1').val(),
        url = $('#cancel_investigation_url').val();
        cancel_investigation(url, {id: id}, $(this));
    })
    //单击确定
    $('.cancelInConfirm').on('click', '.investigation_step3_confirm', function () {
        var param = $("form[name='investigation_step3']").serialize();
        investigation(investigation_url, param, $(this),1);
    });

    /*** step4  未诉时效***/
    //单击取消
    $('.cancelInConfirm').on('click', '.investigation_step4_cancel', function () {
        var id = $('#investigation_id1').val(),
            url = $('#cancel_investigation_url').val();
        cancel_investigation(url, {id: id}, $(this));
    })
    //单击确定
    $('.cancelInConfirm').on('click', '.investigation_step4_confirm', function () {
        var param = $("form[name='investigation_step4']").serialize();
        investigation(investigation_url, param, $(this), 1);
    });

    /*----------------------------------------------------  尽调评估总结  ----------------------------------------------------------*/
    //单击取消
    $('.cancelInConfirm').on('click', '.investigation_summarize_cancel', function () {
        var id =　$('#investigation_id1').val(),
            lock_url = $('#investigation_lock_url').val(),
            obj = $(this);
        $.ajax({
            type: "POST",
            url: lock_url,
            data: {id: id, project_id: project_id, type: 2},
            datatype: "json",
            success: function (data) {
                if (data.code == 200) {
                    $('.project_edit_state').val(1);
                    obj.parent().parent().hide().prev().show().prev().find('img').show();

                    var step10_state = $('#zongJie').find('.step10_state').val();
                    if (step10_state == 2) {
                        $('#zongJie').find('.step10_nothing').text('（暂无数据）');
                        $('#zongJie').find('.step10_nothing').parent().parent().parent().next().hide();
                    } else {
                        $('#zongJie').find('.step10_nothing').text('');
                        $('#zongJie').find('.step10_nothing').parent().parent().parent().next().show();
                    }
                } else if (data.code == 400) {
                    //layer.msg(data.message);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('系统错误');
            }
        })
    })
    //单击确定
    $('.cancelInConfirm').on('click', '.investigation_summarize_confirm', function () {
        var param = $("form[name='investigation_summarize']").serialize();
        investigation(investigation_url, param, $(this), 2);
    });

    /*--------------------------------------------------  借款人及资产情况  -------------------------------------------------------*/
    //单击保存
    $('.cancelInConfirm').on('click', '.stakeholder_borrower_comfirm', function () {
        var stakeholder_borrower_id = $('#stakeholder_borrower_id').val();
        var param = $("form[name='stakeholder_borrower_edit']").serialize();
        param += '&id=' + stakeholder_borrower_id;
        stakeholder(stakeholder_url, param, $(this), 1);
    });

    //添加诉讼情况
    $('#jieKuan').find('.edit_lawsuit_confirm').on('click', function () {
        var obj = $(this),
            stakeholder_borrower_id = $('#stakeholder_borrower_id').val(),
            url = $('#lawsuit_url').val(),
            param = $('form[name="lawsuit_borrower_edit"]').serialize();
        param += '&project_id=' + project_id + '&stakeholder_id=' + stakeholder_borrower_id;
        save_stakeholder(param, url, obj);
    });

    //取消诉讼情况
    $('#jieKuan').find('.edit_lawsuit_cnacel').on('click', function () {
        var url = $('#lawsuit_list_url').val(),
            stakeholder_borrower_id = $('#stakeholder_borrower_id').val(),
            param = {};
        param.project_id = project_id;
        param.stakeholder_id = stakeholder_borrower_id;
        //get_lawsuit_list(param, url, $(this));
        get_lawsuit_list(param, url, $(this), 1);
    });

    /*--------------------------------------------------  保证人及资产情况  -------------------------------------------------------*/
    //单击保存
    $('.cancelInConfirm').on('click', '.stakeholder_warrantor_comfirm', function () {
        var stakeholder_warrantor_id = $('#stakeholder_warrantor_id').val();
        var param = $("form[name='stakeholder_warrantor_edit']").serialize();
        param += '&id=' + stakeholder_warrantor_id;
        stakeholder(stakeholder_url, param, $(this), 3);
    });

    //点击编辑保证人
    $('#baoZheng').find('.topimg').on('click', 'img', function () {
        var stakeholder_warrantor_count = $('#stakeholder_warrantor_count').val();
        var stakeholder_warrantor_ids = $('#stakeholder_warrantor_ids').val();
        var obj = $('#baoZheng').find('.baoZheng').find('.diYa').parent();
        obj.prevAll().remove();
        var html = '';

        var ids_arr = stakeholder_warrantor_ids.split(',');
        if (stakeholder_warrantor_count > 0) {
            for (var i = 1; i <= stakeholder_warrantor_count; i++) {
                if (i == 1) {
                    //html += '<li class="active"><a href="#btab1" data-toggle="tab" data-id="' + ids_arr[i - 1] + '">保证人' + fontString[i - 1] + '<span id="clos">X</span></a></li>';
                    html += '<li class="active"><a href="javascript:;" data-toggle="tab" data-id="' + ids_arr[i - 1] + '" style="width: 120px;">保证人' + fontString[i - 1] + '<span id="clos">X</span></a></li>';
                } else {
                    //html += '<li><a href="#btab' + i + '" data-toggle="tab" data-id="' + ids_arr[i - 1] + '">保证人' + fontString[i - 1] + '<span id="clos">X</span></a></li>';
                    html += '<li><a href="javascript:;" data-toggle="tab" data-id="' + ids_arr[i - 1] + '" style="width: 120px;">保证人' + fontString[i - 1] + '<span id="clos">X</span></a></li>';
                }
            }
        } else {
            //html += '<li class="active"><a href="#btab1" data-toggle="tab" data-id="">保证人一<span id="clos">X</span></a></li>';
            html += '<li class="active"><a href="javascript:;" data-toggle="tab" data-id="" style="width: 120px;">保证人一<span id="clos">X</span></a></li>';
        }
        obj.before(html);
    });

    //删除保证人
    $('#baoZheng').find('.nav-tabs').on('click', 'span', function () {
        var id = $(this).parent().data('id');
        if (parseInt(id) > 0) {
            stakeholderDelete($(this), id, 3, fontString);
        } else {
            var str = $(this).parent().attr('href');
            $(this).parent().parent().remove();
            $(str).remove();
        }
    });

    //保存编辑保证人
    $('.cancelInConfirm').on('click', '.add_warrantor_confirm', function () {
        var ids_arr = $('#stakeholder_warrantor_ids').val().split(','),
            obj = $(this).parent().parent().find('ul li'),
            arr = [];

        $.each(obj, function (i, n) {
            if (obj.length > 0) {
                if ((obj.length - 1) != i) {
                    arr.push($(this).find('a').data('id'));
                }
            }
        });

        //解锁
        var id = $('#stakeholder_warrantor_id').val();
        set_investigation_stakeholder_unlocking({id: id, project_id: project_id, type: 2, stakeholder_type: 2}, stakeholder_lock_url, $(this));
        get_stakeholder_list(ids_arr, arr, 3, $(this), fontString, 1);
    });

    //取消编辑保证人
    $('.cancelInConfirm').on('click', '.add_warrantor_cancel', function () {
        var ids_arr = $('#stakeholder_warrantor_ids').val().split(','),
            obj = $(this).parent().parent().find('ul li'),
            arr = [];

        $.each(obj, function (i, n) {
            if (obj.length > 0) {
                if ((obj.length - 1) != i) {
                    arr.push($(this).find('a').data('id'));
                }
            }
        });

        //解锁
        var id = $('#stakeholder_warrantor_id').val();
        set_investigation_stakeholder_unlocking({id: id, project_id: project_id, type: 2, stakeholder_type: 2}, stakeholder_lock_url, $(this));
        get_stakeholder_list(ids_arr, arr, 3, $(this), fontString, 1);
    });

    //切换保证人
    $('#baoZheng').find('.nav-tabs').on('click', 'li', function () {
        $(this).parent().children().each(function (i) {
            $(this).removeClass('active');
        });
        $(this).addClass('active');
        var id = $(this).find('a').data('id');
        get_stakeholder_info(id, stakeholder_info_url, 3);
    });

    //添加诉讼情况
    $('#baoZheng').find('.edit_lawsuit_confirm').on('click', function () {
        var obj = $(this),
            stakeholder_warrantor_id = $('#stakeholder_warrantor_id').val(),
            url = $('#lawsuit_url').val(),
            param = $('form[name="lawsuit_warrantor_edit"]').serialize();
        param += '&project_id=' + project_id + '&stakeholder_id=' + stakeholder_warrantor_id;

        save_stakeholder(param, url, obj);
    });

    //取消诉讼情况
    $('#baoZheng').find('.edit_lawsuit_cnacel').on('click', function () {
        var url = $('#lawsuit_list_url').val(),
            stakeholder_warrantor_id = $('#stakeholder_warrantor_id').val(),
            param = {};
        param.project_id = project_id;
        param.stakeholder_id = stakeholder_warrantor_id;
        //get_lawsuit_list(param, url, $(this));
        get_lawsuit_list(param, url, $(this), 3);
    });

    /*--------------------------------------------------- 抵押人及抵押物情况  --------------------------------------------------------*/
    //单击保存
    $('.cancelInConfirm').on('click', '.stakeholder_pledger_comfirm', function () {
        var param = $("form[name='stakeholder_pledger_edit']").serialize();
        var stakeholder_pledger_id = $('#stakeholder_pledger_id').val();
        param += '&id=' + stakeholder_pledger_id;
        stakeholder(stakeholder_url, param, $(this), 2);
    });

    //点击编辑抵押人
    $('#diYa').find('.topimg').on('click', 'img', function () {
        var stakeholder_pledger_count = $('#stakeholder_pledger_count').val();
        var stakeholder_pledger_ids = $('#stakeholder_pledger_ids').val();
        var obj = $('#diYa').find('.di-ya').find('.diYa').parent();
        obj.prevAll().remove();
        var html = '';

        var ids_arr = stakeholder_pledger_ids.split(',');
        if (stakeholder_pledger_count > 0) {
            for (var i = 1; i <= stakeholder_pledger_count; i++) {
                if (i == 1) {
                    //html += '<li class="active"><a href="#btab1" data-toggle="tab" data-id="' + ids_arr[i - 1] + '">抵押人' + fontString[i - 1] + '<span id="clos">X</span></a></li>';
                    html += '<li class="active"><a href="javascript:;" data-toggle="tab" data-id="' + ids_arr[i - 1] + '" style="width: 120px;">抵押人' + fontString[i - 1] + '<span id="clos">X</span></a></li>';
                } else {
                    //html += '<li><a href="#btab' + i + '" data-toggle="tab" data-id="' + ids_arr[i - 1] + '">抵押人' + fontString[i - 1] + '<span id="clos">X</span></a></li>';
                    html += '<li><a href="javascript:;" data-toggle="tab" data-id="' + ids_arr[i - 1] + '" style="width: 120px;">抵押人' + fontString[i - 1] + '<span id="clos">X</span></a></li>';
                }
            }
        } else {
            //html += '<li class="active"><a href="#btab1" data-toggle="tab" data-id="">抵押人一<span id="clos">X</span></a></li>';
            html += '<li class="active"><a href="javascript:;" data-toggle="tab" data-id="" style="width: 120px;">抵押人一<span id="clos">X</span></a></li>';
        }
        obj.before(html);
    });

    //删除抵押人
    $('#diYa').find('.nav-tabs').on('click', 'span', function () {
        var id = $(this).parent().data('id');
        if (parseInt(id) > 0) {
            stakeholderDelete($(this), id, 2, fontString);
        } else {
            var str = $(this).parent().attr('href');
            $(this).parent().parent().remove();
            $(str).remove();
        }
    });

    //取消编辑抵押人
    $('.cancelInConfirm').on('click', '.add_pledger_cancel', function () {
        var ids_arr = $('#stakeholder_pledger_ids').val().split(','),
            obj = $(this).parent().parent().find('ul li'),
            arr = [];

        $.each(obj, function (i, n) {
            if (obj.length > 0) {
                if ((obj.length - 1) != i) {
                    arr.push($(this).find('a').data('id'));
                }
            }
        });

        //解锁
        var id = $('#stakeholder_pledger_id').val();
        set_investigation_stakeholder_unlocking({id: id, project_id: project_id, type: 2, stakeholder_type: 2}, stakeholder_lock_url, $(this));

        get_stakeholder_list(ids_arr, arr, 2, $(this), fontString, 1);
    });

    //保存编辑抵押人
    $('.cancelInConfirm').on('click', '.add_pledger_confirm', function () {
        var ids_arr = $('#stakeholder_pledger_ids').val().split(','),
            obj = $(this).parent().parent().find('ul li'),
            arr = [];

        $.each(obj, function (i, n) {
            if (obj.length > 0) {
                if ((obj.length - 1) != i) {
                    arr.push($(this).find('a').data('id'));
                }
            }
        });

        //解锁
        var id = $('#stakeholder_pledger_id').val();
        set_investigation_stakeholder_unlocking({id: id, project_id: project_id, type: 2, stakeholder_type: 2}, stakeholder_lock_url, $(this));

        get_stakeholder_list(ids_arr, arr, 2, $(this), fontString, 1);
    });

    //切换抵押人
    $('#diYa').find('.nav-tabs').on('click', 'li', function () {
        $(this).parent().children().each(function (i) {
            $(this).removeClass('active');
        });
        $(this).addClass('active');
        var id = $(this).find('a').data('id');
        get_stakeholder_info(id, stakeholder_info_url, 2);
    });

    //添加诉讼情况
    $('#diYa').find('.edit_lawsuit_confirm').on('click', function () {
        var obj = $(this),
            stakeholder_pledger_id = $('#stakeholder_pledger_id').val(),
            url = $('#lawsuit_url').val(),
            param = $('form[name="lawsuit_pledger_edit"]').serialize();
        param += '&project_id=' + project_id + '&stakeholder_id=' + stakeholder_pledger_id;

        save_stakeholder(param, url, obj);
    });

    //取消诉讼情况
    $('#diYa').find('.edit_lawsuit_cnacel').on('click', function () {
        var url = $('#lawsuit_list_url').val(),
            stakeholder_pledger_id = $('#stakeholder_pledger_id').val(),
            param = {};
        param.project_id = project_id;
        param.stakeholder_id = stakeholder_pledger_id;
        //get_lawsuit_list(param, url, $(this));
        get_lawsuit_list(param, url, $(this), 2);
    });

    /*---------------------------------------------------  其它承债人及资产情况  --------------------------------------------------------*/
    //单击保存
    $('.cancelInConfirm').on('click', '.stakeholder_other_comfirm', function () {
        var param = $("form[name='stakeholder_other_edit']").serialize();
        var stakeholder_other_id = $('#stakeholder_other_id').val();
        param += '&id=' + stakeholder_other_id;
        stakeholder(stakeholder_url, param, $(this), 4);
    });

    //点击编辑承债人
    $('#qiTa').find('.topimg').on('click', 'img', function () {
        var stakeholder_other_ids = $('#stakeholder_other_ids').val();
        var stakeholder_other_count = $('#stakeholder_other_count').val();
        var obj = $('#qiTa').find('.chengZhai').find('.diYa').parent();
        obj.prevAll().remove();
        var html = '';

        var ids_arr = stakeholder_other_ids.split(',');
        if (stakeholder_other_count > 0) {
            for (var i = 1; i <= stakeholder_other_count; i++) {
                if (i == 1) {
                    //html += '<li class="active"><a href="#btab1" data-toggle="tab" data-id="' + ids_arr[i - 1] + '">承债人' + fontString[i - 1] + '<span id="clos">X</span></a></li>';
                    html += '<li class="active"><a href="javascript:;" data-toggle="tab" data-id="' + ids_arr[i - 1] + '" style="width: 120px;">承债人' + fontString[i - 1] + '<span id="clos">X</span></a></li>';
                } else {
                    //html += '<li><a href="#btab' + i + '" data-toggle="tab" data-id="' + ids_arr[i - 1] + '">承债人' + fontString[i - 1] + '<span id="clos">X</span></a></li>';
                    html += '<li><a href="javascript:;" data-toggle="tab" data-id="' + ids_arr[i - 1] + '" style="width: 120px;">承债人' + fontString[i - 1] + '<span id="clos">X</span></a></li>';
                }
            }
        } else {
            //html += '<li class="active"><a href="#btab1" data-toggle="tab" data-id="">承债人一<span id="clos">X</span></a></li>';
            html += '<li class="active"><a href="javascript:;" data-toggle="tab" data-id="" style="width: 120px;">承债人一<span id="clos">X</span></a></li>';
        }
        obj.before(html);
    });

    //删除承债人
    $('#qiTa').find('.nav-tabs').on('click', 'span', function () {
        var id = $(this).parent().data('id');
        if (parseInt(id) > 0) {
            stakeholderDelete($(this), id, 4, fontString);
        } else {
            var str = $(this).parent().attr('href');
            $(this).parent().parent().remove();
            $(str).remove();
        }
    });

    //保存编辑承债人
    $('.cancelInConfirm').on('click', '.add_other_confirm', function () {
        var ids_arr = $('#stakeholder_other_ids').val().split(','),
            obj = $(this).parent().parent().find('ul li'),
            arr = [];

        $.each(obj, function (i, n) {
            if (obj.length > 0) {
                if ((obj.length - 1) != i) {
                    arr.push($(this).find('a').data('id'));
                }
            }
        });

        //解锁
        var id = $('#stakeholder_other_id').val();
        set_investigation_stakeholder_unlocking({id: id, project_id: project_id, type: 2, stakeholder_type: 4}, stakeholder_lock_url, $(this));
        get_stakeholder_list(ids_arr, arr, 4, $(this), fontString, 1);
    });

    //取消编辑其它承债人
    $('.cancelInConfirm').on('click', '.add_other_cancel', function () {
        var ids_arr = $('#stakeholder_other_ids').val().split(','),
            obj = $(this).parent().parent().find('ul li'),
            arr = [];

        $.each(obj, function (i, n) {
            if (obj.length > 0) {
                if ((obj.length - 1) != i) {
                    arr.push($(this).find('a').data('id'));
                }
            }
        });

        //解锁
        var id = $('#stakeholder_other_id').val();
        set_investigation_stakeholder_unlocking({id: id, project_id: project_id, type: 2, stakeholder_type: 4}, stakeholder_lock_url, $(this));
        get_stakeholder_list(ids_arr, arr, 4, $(this), fontString, 1);
    });

    //切换承债人
    $('#qiTa').find('.nav-tabs').on('click', 'li', function () {
        $(this).parent().children().each(function (i) {
            $(this).removeClass('active');
        });
        $(this).addClass('active');
        var id = $(this).find('a').data('id');
        get_stakeholder_info(id, stakeholder_info_url, 4);
    });

    //添加诉讼情况
    $('#qiTa').find('.edit_lawsuit_confirm').on('click', function () {
        var obj = $(this),
            stakeholder_other_id = $('#stakeholder_other_id').val(),
            url = $('#lawsuit_url').val(),
            param = $('form[name="lawsuit_other_edit"]').serialize();
        param += '&project_id=' + project_id + '&stakeholder_id=' + stakeholder_other_id;

        save_stakeholder(param, url, obj);
    });

    //取消诉讼情况
    $('#qiTa').find('.edit_lawsuit_cnacel').on('click', function () {
        var url = $('#lawsuit_list_url').val(),
            stakeholder_other_id = $('#stakeholder_other_id').val(),
            param = {};
        param.project_id = project_id;
        param.stakeholder_id = stakeholder_other_id;
        //get_lawsuit_list(param, url, $(this));
        get_lawsuit_list(param, url, $(this), 4);
    });

    /*--------------------------------------------------- 删除诉讼情况  --------------------------------------------------------*/
    //删除诉讼情况
    /*$('.she-su-qing-kuang-edit').on('click', 'tr td input[type="button"]', function () {
        var id = $(this).prev().val(),
            url = $('#lawsuit_delete_url').val(),
            state = true;
        delete_modal_lawsuit(id, url, $(this));
    });*/
})

/**
 * 模态框删除
 * @param id
 * @param url 地址
 * @param obj 当前对象
 */
function delete_modal_lawsuit(id, url, obj) {
    $('#deleModal .modal-footer').on('click', '#modal-cancel', function () {
        obj.parent().parent().remove();

        if (parseInt(id) > 0) {
            param = {};
            param.id = id;

            $.ajax({
                type: "POST",
                url: url,
                data: param,
                datatype: "json",
                success: function (data) {
                    if (data.code == 200) {
                        layer.msg(data.message);
                    } else if (data.code == 400) {
                        layer.msg(data.message);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('系统错误');
                }
            });
        }
    });
}

/**
 * 添加诉讼
 * @param param 参数
 * @param url 保存地址
 * @param obj 当前对象
 */
function save_stakeholder(param, url, obj) {
    $.ajax({
        type: "POST",
        url: url,
        data: param,
        datatype: "json",
        success: function (data) {
            if (data.code == 200) {
                layer.msg(data.message);
                $('.project_edit_state').val(1);
                set_lawsuit_list(data.data.res, obj, 0)
                /*var html = '',
                    length = data.data.res.length;

                    if (length>0) {
                    $.each(data.data.res, function (i, n) {
                        html += '<tr><td><input type="text" name="info[' + i + '][records_number]" class="records_number' + i + '" value="' + n.records_number + '"/>'+
                            '</td> <td> <input type="text" name="info[' + i +  '][accuser]" class="accuser' + i + '" value="' + n.accuser + '"/>' +
                            '</td> <td> <input type="text" name="info[' + i + '][defendant]" class="defendant' + i + '" value="' + n.defendant + '"style="color:#333!important"/>' +
                            '</td> <td> <input type="text" name="info[' + i + '][money]" class="money' + i + '" value="' + n.money + '"/>' +
                            '</td> <td> <input type="text" name="info[' + i + '][court]" class="court' + i + '" value="' + n.court + '"/>' +
                            '</td> <td> <input type="text" name="info[' + i + '][lawsuit_content]" class="lawsuit_content' + i + '" value="' + n.lawsuit_content + '"/>' +
                            '</td> <td>' +
                            '<input type="hidden" name="info[' + i + '][id]" id="lawsuit_id' + i + '" value="' + n.id + '"/>' +
                            '<input type="button" class="remove delete_investigation_lawsuit" data-id="' + n.id + '" value="删除"/> </td> </tr>';
                    });
                }
                obj.parent().prev().find('.td_top').nextAll().remove();
                obj.parent().prev().find('.td_top').after(html);*/
            } else if (data.code == 400) {
                layer.msg(data.message);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.msg('系统错误');
        }
    });
}

function set_lawsuit_list(data, obj, lawsuit_type) {
    //只读
    obj.parent().parent().hide().prev().show().prev().find('img').show();
    obj.parent().parent().hide().prev().find('table').find("tr:gt(0)").remove();
    var html = '',
        length = data.length;
    if (length > 0) {
        $.each(data, function (i, n) {

            html +=
                '<tr>' +
                '<td>' +
                '<span class = "txt-cut-1" title = "' + n.records_number + '" >' +
                n.records_number +
                '</span>'
                + '</td>' +
                '<td>' +
                '<span class = "txt-cut-1" title = "' + n.accuser + '">' +
                n.accuser +
                '</span>'

                + '</td>' +
                '<td style = "background: #fff!important;">' +
                '<span class = "txt-cut-1" title = "' + n.defendant + '" style = "color:#333!important">' +
                n.defendant +
                '</span>'
                + '</td>' +
                '<td>' +
                '<span class = "txt-cut-1" title = "' + n.money + '">' +
                n.money +
                '</span>'
                + '</td>' +
                '<td>' +
                '<span class = "txt-cut-1" title = "' + n.court + '">' +
                n.court +
                '</span>'
                + '</td>' +
                '<td>' +
                '<span class = "txt-cut-1" title = "' + n.lawsuit_content + '">' +
                n.lawsuit_content +
                '</span>'
                + '</td>' +
                '</tr>';
        });
    }
    obj.parent().parent().prev().find('table').append(html);

    switch (lawsuit_type) {
        case 1:
            if (length > 0) {
                $('#jieKuan').find('.step2_nothing').text('');
                $('#jieKuan').find('.step2_nothing').parent().parent().next().show();
            } else {
                $('#jieKuan').find('.step2_nothing').text('（暂无数据）');
                $('#jieKuan').find('.step2_nothing').parent().parent().next().hide();
            }
            break;
        case 2:
            if (length > 0) {
                $('#diYa').find('.step2_nothing').text('');
                $('#diYa').find('.step2_nothing').parent().parent().next().show();
            } else {
                $('#diYa').find('.step2_nothing').text('（暂无数据）');
                $('#diYa').find('.step2_nothing').parent().parent().next().hide();
            }
            break;
        case 3:
            if (length > 0) {
                $('#baoZheng').find('.step2_nothing').text('');
                $('#baoZheng').find('.step2_nothing').parent().parent().next().show();
            } else {
                $('#baoZheng').find('.step2_nothing').text('（暂无数据）');
                $('#baoZheng').find('.step2_nothing').parent().parent().next().hide();
            }
            break;
        case 4:
            if (length > 0) {
                $('#qiTa').find('.step2_nothing').text('');
                $('#qiTa').find('.step2_nothing').parent().parent().next().show();
            } else {
                $('#qiTa').find('.step2_nothing').text('（暂无数据）');
                $('#qiTa').find('.step2_nothing').parent().parent().next().hide();
            }
            break;
        default:
    }

    //编辑
    var html = '',
        length = data.length;

    if (length>0) {
        $.each(data, function (i, n) {
            html += '<tr><td><input type="text" name="info[' + i + '][records_number]" class="records_number' + i + '" value="' + n.records_number + '"/>'+
                '</td> <td> <input type="text" name="info[' + i +  '][accuser]" class="accuser' + i + '" value="' + n.accuser + '"/>' +
                '</td> <td> <input type="text" name="info[' + i + '][defendant]" class="defendant' + i + '" value="' + n.defendant + '"style="color:#333!important"/>' +
                '</td> <td> <input type="text" name="info[' + i + '][money]" class="money' + i + '" value="' + n.money + '"/>' +
                '</td> <td> <input type="text" name="info[' + i + '][court]" class="court' + i + '" value="' + n.court + '"/>' +
                '</td> <td> <input type="text" name="info[' + i + '][lawsuit_content]" class="lawsuit_content' + i + '" value="' + n.lawsuit_content + '"/>' +
                '</td> <td>' +
                '<input type="hidden" name="info[' + i + '][id]" id="lawsuit_id' + i + '" value="' + n.id + '"/>' +
                '<input type="button" class="remove delete_investigation_lawsuit" data-id="' + n.id + '" value="删除"/> </td> </tr>';
        });
    }
    obj.parent().prev().find('.td_top').nextAll().remove();
    obj.parent().prev().find('.td_top').after(html);
}

/**
 * 获取诉讼情况列表
 * @param param
 * @param url
 * @param obj
 */
function get_lawsuit_list(param, url, obj, lawsuit_type) {
    $.ajax({
        type: "POST",
        url: url,
        data: param,
        datatype: "json",
        success: function (data) {
            if (data.code == 200) {
                $('.project_edit_state').val(1);
                set_lawsuit_list(data.data.res, obj, lawsuit_type);
                /*obj.parent().parent().hide().prev().show().prev().find('img').show();
                obj.parent().parent().hide().prev().find('table').find("tr:gt(0)").remove();
                var html = '',
                    length = data.data.res.length;
                if (length > 0) {
                    $.each(data.data.res, function (i, n) {

                        html +=
                            '<tr>' +
                            '<td>' +
                            '<span class = "txt-cut-1" title = "' + n.records_number + '" >' +
                            n.records_number +
                            '</span>'
                            + '</td>' +
                            '<td>' +
                            '<span class = "txt-cut-1" title = "' + n.accuser + '">' +
                            n.accuser +
                            '</span>'

                            + '</td>' +
                            '<td style = "background: #fff!important;">' +
                            '<span class = "txt-cut-1" title = "' + n.defendant + '" style = "color:#333!important">' +
                            n.defendant +
                            '</span>'
                            + '</td>' +
                            '<td>' +
                            '<span class = "txt-cut-1" title = "' + n.money + '">' +
                            n.money +
                            '</span>'
                            + '</td>' +
                            '<td>' +
                            '<span class = "txt-cut-1" title = "' + n.court + '">' +
                            n.court +
                            '</span>'
                            + '</td>' +
                            '<td>' +
                            '<span class = "txt-cut-1" title = "' + n.lawsuit_content + '">' +
                            n.lawsuit_content +
                            '</span>'
                            + '</td>' +
                            '</tr>';
                    });
                }
                obj.parent().parent().hide().prev().find('table').append(html);

                switch (lawsuit_type) {
                    case 1:
                        if (length > 0) {
                            $('#jieKuan').find('.step2_nothing').text('');
                            $('#jieKuan').find('.step2_nothing').parent().parent().next().show();
                        } else {
                            $('#jieKuan').find('.step2_nothing').text('（暂无数据）');
                            $('#jieKuan').find('.step2_nothing').parent().parent().next().hide();
                        }
                        break;
                    case 2:
                        if (length > 0) {
                            $('#diYa').find('.step2_nothing').text('');
                            $('#diYa').find('.step2_nothing').parent().parent().next().show();
                        } else {
                            $('#diYa').find('.step2_nothing').text('（暂无数据）');
                            $('#diYa').find('.step2_nothing').parent().parent().next().hide();
                        }
                        break;
                    case 3:
                        if (length > 0) {
                            $('#baoZheng').find('.step2_nothing').text('');
                            $('#baoZheng').find('.step2_nothing').parent().parent().next().show();
                        } else {
                            $('#baoZheng').find('.step2_nothing').text('（暂无数据）');
                            $('#baoZheng').find('.step2_nothing').parent().parent().next().hide();
                        }
                        break;
                    case 4:
                        if (length > 0) {
                            $('#qiTa').find('.step2_nothing').text('');
                            $('#qiTa').find('.step2_nothing').parent().parent().next().show();
                        } else {
                            $('#qiTa').find('.step2_nothing').text('（暂无数据）');
                            $('#qiTa').find('.step2_nothing').parent().parent().next().hide();
                        }
                        break;
                    default:
                }*/

            } else if (data.code == 400) {
                layer.msg(data.message);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.msg('系统错误');
        }
    });
}

/**
 * 显示干系人列表
 * @param ids 存在的ids
 * @param data 要显示的数据data-id
 * @param type 类型
 * @param obj  点击对象
 */
function get_stakeholder_list(ids, data, type, obj, fontString, state) {
    var name = '',
        html = '';
    switch (type) {
        case 2:
            name = '抵押人';
            $('#stakeholder_pledger_ids').val(data.join(','));
            break;
        case 3:
            name = '保证人';
            $('#stakeholder_warrantor_ids').val(data.join(','));
            break;
        case 4:
            name = '承债人';
            $('#stakeholder_other_ids').val(data.join(','));
            break;
    }
    if (data.length > 0) {
        $.each(data, function (i, n) {
            if (i <= (ids.length - 1)) {
                if (i == 0) {
                    //html += '<li class="active"><a href="#btab' + (i + 1) + '" data-toggle="tab" data-id="' + ids[i] + '">' + name + fontString[i] + '</a></li>';
                    html += '<li class="active"><a href="javascript:;" data-toggle="tab" data-id="' + ids[i] + '">' + name + fontString[i] + '</a></li>';
                } else {
                    //html += '<li><a href="#btab' + (i + 1) + '" data-toggle="tab" data-id="' + ids[i] + '">' + name + fontString[i] + '</a></li>';
                    html += '<li><a href="javascript:;" data-toggle="tab" data-id="' + ids[i] + '">' + name + fontString[i] + '</a></li>';
                }
            } else {
                //html += '<li><a href="#btab' + (i + 1) + '" data-toggle="tab" data-id="">' + name + fontString[i] + '</a></li>';
                html += '<li><a href="javascript:;" data-toggle="tab" data-id="">' + name + fontString[i] + '</a></li>';
            }
        });
    } else {
        //html += '<li class="active"><a href="#btab1" data-toggle="tab" data-id="">' + name + '一</a></li>';
        html += '<li class="active"><a href="javascript:;" data-toggle="tab" data-id="">' + name + '一</a></li>';
    }
    if (state == 1) {
        obj.parent().parent().hide().prev().show().prev().find('img').show();
        obj.parent().parent().prev().html(html);
    } else {
        obj.parent().parent().prev().html(html);
    }
}

/**
 * 详情——干系人及资产情况
 * @param id
 * @param stakeholder_type
 */
function get_stakeholder_info(id, stakeholder_info_url, stakeholder_type) {
    var param = {};
    param.id = id;
    param.stakeholder_type = stakeholder_type;

    $.ajax({
        type: "POST", //类型 POST GET
        url: stakeholder_info_url,
        data: param,
        datatype: "json",
        //成功返回之后调用的函数
        success: function (data) {
            if (data.code == 200) {
                //layer.msg('加载成功');
                stakeholderSetValue(data.data.res.model, stakeholder_type, 2, data.data.res.lawsuitList);
            }
        },
        //调用出错执行的函数
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.msg('系统错误');
        }
    });
}

/**
 * 保存——干系人及资产情况
 * @param stakeholder_url 保存地址
 * @param param 传参
 * @param obj  点击对象
 * @param type 类型
 */
function stakeholder(stakeholder_url, param, obj, type) {
    $.ajax({
        type: "POST",
        url: stakeholder_url,
        data: param,
        datatype: "json",
        success: function (data) {
            //var model = data.data.res;
            var model = data.data.res.model;
            if (data.code == 200) {
                layer.msg('保存成功');
                $('.project_edit_state').val(1);
                obj.parent().parent().hide().prev().show().prev().find('img').show();
                stakeholderSetValue(model, type, 1, data.data.res.lawsuitList);
                switch (type) {
                    case 1:
                        $('#stakeholder_borrower_id').val(model.id);
                        $('#jieKuan').find('.topimg').next().children('p').hide();
                        $('#jieKuan').find('.topimg').next().children('table').show();
                        break;
                    case 2:
                        $.each($('#diYa').find('.topimg').next().find('li'), function (i, n) {
                            if ($(this).hasClass('active')) {
                                $(this).find('a').data('id', model.id);
                                $('#diYa').find('.di-ya').eq(i).find('a').data('id', model.id);
                            }
                        });

                        var ids_arr = $('#stakeholder_pledger_ids').val().split(',');
                        $.each(ids_arr, function (i, n) {
                            if (n == '') {
                                ids_arr.splice($.inArray('', ids_arr), 1);
                            }
                        });
                        var index = $.inArray(model.id, ids_arr);
                        if (index == -1) {
                            ids_arr.push(model.id);
                        }
                        $('#stakeholder_pledger_ids').val(ids_arr.join(','));
                        $('#stakeholder_pledger_id').val(model.id);
                        $('#stakeholder_pledger_count').val(ids_arr.length);

                        break;
                    case 3:
                        $.each($('#baoZheng').find('.topimg').next().find('li'), function (i, n) {
                            if ($(this).hasClass('active')) {
                                $(this).find('a').data('id', model.id);
                                $('#baoZheng').find('.baoZheng').eq(i).find('a').data('id', model.id);
                            }
                        });

                        var ids_arr = $('#stakeholder_warrantor_ids').val().split(',');
                        $.each(ids_arr, function (i, n) {
                            if (n == '') {
                                ids_arr.splice($.inArray('', ids_arr), 1);
                            }
                        });
                        var index = $.inArray(model.id, ids_arr);
                        if (index == -1) {
                            ids_arr.push(model.id);
                        }
                        $('#stakeholder_warrantor_ids').val(ids_arr.join(','));
                        $('#stakeholder_warrantor_id').val(model.id);
                        $('#stakeholder_warrantor_count').val(ids_arr.length);

                        break;
                    case 4:
                        $.each($('#qiTa').find('.topimg').next().find('li'), function (i, n) {
                            if ($(this).hasClass('active')) {
                                $(this).find('a').data('id', model.id);
                                $('#qiTa').find('.chengZhai').eq(i).find('a').data('id', model.id);
                            }
                        });

                        var ids_arr = $('#stakeholder_other_ids').val().split(',');
                        $.each(ids_arr, function (i, n) {
                            if (n == '') {
                                ids_arr.splice($.inArray('', ids_arr), 1);
                            }
                        });

                        var index = $.inArray(model.id, ids_arr);
                        if (index == -1) {
                            ids_arr.push(model.id);
                        }
                        $('#stakeholder_other_ids').val(ids_arr.join(','));
                        $('#stakeholder_other_id').val(model.id);
                        $('#stakeholder_other_count').val(ids_arr.length);

                        break;
                }
            } else if (data.code == 400) {
                layer.msg(data.message);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.msg('系统错误');
        }
    });
}

/**
 * 删除干系人用户资产情况
 * @param obj 点击对象
 * @param id 删除id
 * @param type 类型
 */
function stakeholderDelete(obj, id, type, fontString) {
    var url = $('#stakeholder_delete_url').val();
    var param = {};
    param.id = id;
    param.stakeholder_type = type;

    $.ajax({
        type: "POST",
        url: url,
        data: param,
        datatype: "json",
        success: function (data) {
            var model = data.data.res;
            if (data.code == 200) {
                layer.msg('删除成功');
                switch (type) {
                    case 2:
                        $('#stakeholder_pledger_id').val('');

                        var str = obj.parent().attr('href');
                        obj.parent().parent().remove();
                        //$(str).remove();

                        var ids_arr = [],
                            arr = [],
                            obj2 = $('#diYa').find('.di-ya').find('li');
                        $.each(obj2, function (i, n) {
                            if (obj2.length > 0) {
                                if ((obj2.length - 1) != i) {
                                    var id = $(this).find('a').data('id');
                                    arr.push(id);
                                    if (id != '') {
                                        ids_arr.push(id);
                                    }
                                }
                            }
                        });
                        $('#stakeholder_pledger_ids').val(ids_arr.join(','));
                        $('#stakeholder_pledger_count').val(ids_arr.length);
                        get_stakeholder_list(ids_arr, arr, 2, $('#diYa').find('.add_pledger_confirm'), fontString, 2);
                        break;
                    case 3:
                        $('#stakeholder_warrantor_id').val('');

                        var str = obj.parent().attr('href');
                        obj.parent().parent().remove();
                        //$(str).remove();

                        var ids_arr = [],
                            arr = [],
                            obj2 = $('#baoZheng').find('.baoZheng').find('li');
                        $.each(obj2, function (i, n) {
                            if (obj2.length > 0) {
                                if ((obj2.length - 1) != i) {
                                    var id = $(this).find('a').data('id');
                                    arr.push(id);
                                    if (id != '') {
                                        ids_arr.push(id);
                                    }
                                }
                            }
                        });

                        $('#stakeholder_warrantor_ids').val(ids_arr.join(','));
                        $('#stakeholder_warrantor_count').val(ids_arr.length);
                        get_stakeholder_list(ids_arr, arr, 3, $('#baoZheng').find('.add_warrantor_confirm'), fontString, 2);
                        break;
                    case 4:
                        $('#stakeholder_other_id').val('');

                        var str = obj.parent().attr('href');
                        obj.parent().parent().remove();
                        //$(str).remove();

                        var ids_arr = [],
                            arr = [],
                            obj2 = $('#qiTa').find('.chengZhai').find('li');
                        $.each(obj2, function (i, n) {
                            if (obj2.length > 0) {
                                if ((obj2.length - 1) != i) {
                                    var id = $(this).find('a').data('id');
                                    arr.push(id);
                                    if (id != '') {
                                        ids_arr.push(id);
                                    }
                                }
                            }
                        });

                        $('#stakeholder_other_ids').val(ids_arr.join(','));
                        $('#stakeholder_other_count').val(ids_arr.length);

                        get_stakeholder_list(ids_arr, arr, 4, $('#qiTa').find('.add_other_confirm'), fontString, 2);
                        break;
                }
            } else if (data.code == 400) {
                layer.msg(data.message);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.msg('系统错误');
        }
    });
}

function get_lawsuit_edit(lawsuitList) {
    var html = '';
    if (lawsuitList.length > 0) {
        $.each(lawsuitList, function (i, n) {
            html += '<tr>' +
                '<td>' +
                '	 <input type="text" name="info[' + i + '][records_number]" class="records_number' + i + '" value="' + n.records_number + '"/>' +
                '</td>' +
                '<td>' +
                '	 <input type="text" name="info[' + i + '][accuser]" class="accuser' + i + '" value="' + n.accuser + '"/>' +
                '</td>' +
                '<td>' +
                '	 <input type="text" name="info[' + i + '][defendant]" class="defendant' + i + '" value="' + n.defendant + '"/>' +
                '</td>' +
                '<td>' +
                '	 <input type="text" name="info[' + i + '][money]" class="money' + i + '" value="' + n.money + '"/>' +
                '</td>' +
                '<td>' +
                '	 <input type="text" name="info[' + i + '][court]" class="court' + i + '" value="' + n.court + '"/>' +
                '</td>' +
                '<td>' +
                '	 <input type="text" name="info[' + i + '][lawsuit_content]" class="lawsuit_content' + i + '" value="' + n.lawsuit_content + '"/>' +
                '</td>' +
                '<td>' +
                '<input type="hidden" name="info[' + i + '][id]" id="lawsuit_id' + i + '" value="' + n.id + '"/>' +
                '<input type="button" class="remove" data-toggle="modal" data-target="#deleModal" value="删除" />' +
                '</td>' +
                '</tr>';
        });
    }
    return html;
}

function get_lawsuit_readonly(lawsuitList) {
    var html = '';
    if (lawsuitList.length > 0) {
        $.each(lawsuitList, function (i, n) {
            html +=
                '<tr>' +
                '<td>' + n.records_number + '</td>' +
                '<td>' + n.accuser + '</td>' +
                '<td>' + n.defendant + '</td>' +
                '<td>' + n.money + '</td>' +
                '<td>' + n.court + '</td>' +
                '<td>' + n.lawsuit_content + '</td>' +
                '</tr>';
        });
    }
    return html;
}

/**
 * 设置表单值——干系人及资产情况
 * @param model  object
 */
function stakeholderSetValue(model, type, state, lawsuitList) {
    //'stakeholderType' => [1 => '债务人', 2 => '抵押人', 3 => '保证人', 4 => '其他承债人'],
    var obj1, obj2;

    //隐藏显示
    var step1_state = 2,
        step3_state = 2,
        step4_state = 2,
        step5_state1 = 2,
        step5_state = 2,
        step6_state = 2,
        step7_state = 2;

    //工商信息
    if (!isVariable1Empty(model.stakeholder_title) || !isVariable1Empty(model.registered_capital) || !isVariable1Empty(model.registered_address) || !isVariable1Empty(model.legal_representative)
        || !isVariable1Empty(model.scope_of_business) || !isVariable1Empty(model.proportion) || !isVariable1Empty(model.borrower) || !isVariable1Empty(model.buy_back))
        step1_state = 1;
    //列失信
    if (!isVariable1Empty(model.faith) || !isVariable1Empty(model.limit_high) || !isVariable1Empty(model.block_list) || !isVariable1Empty(model.block_value))
        step3_state = 1;
    //现场状态
    if (!isVariable1Empty(model.rent) || !isVariable1Empty(model.live) || !isVariable1Empty(model.interview))
        step6_state = 1;
    //回现评估
    if (!isVariable1Empty(model.payment_reservation) || !isVariable1Empty(model.reservation_evidence) || !isVariable1Empty(model.payment_radical) || !isVariable1Empty(model.radical_evidence))
        step7_state = 1;
    //详情
    if (!isVariable1Empty(model.guarantee_scope) || !isVariable1Empty(model.guarantee) || !isVariable1Empty(model.seal_order)
        || !isVariable1Empty(model.other_mortgage) || !isVariable1Empty(model.evaluate_price) || !isVariable1Empty(model.auction_price) || !isVariable1Empty(model.market_price))
        step5_state = 1;
    //债权基本情况——其它补充
    if (!isVariable1Empty(model.update_log) || !isVariable1Empty(model.other_guarantee) || !isVariable1Empty(model.seal_order) || !isVariable1Empty(model.other_mortgage))
        step4_state = 1;
    //债权基本情况——市场询价
    if (!isVariable1Empty(model.evaluate_price) || !isVariable1Empty(model.auction_price) || !isVariable1Empty(model.identical_price)
        || !isVariable1Empty(model.recently_price) || !isVariable1Empty(model.buyer_price) || !isVariable1Empty(model.rental_price) || !isVariable1Empty(model.tax_price))
        step5_state1 = 1;

    if (type != 1) {
        switch (type) {
            case 2:
                obj1 = $('form[name="stakeholder_pledger_readonly"]');
                obj2 = $('form[name="stakeholder_pledger_edit"]');
                $('#stakeholder_pledger_id').val(model.id);

                var html1 = get_lawsuit_readonly(lawsuitList);
                var html2 = get_lawsuit_edit(lawsuitList);
                $('#diYa').find('form[name="lawsuit_pledger_readonly"]').find('table').find('tr:gt(0)').remove();
                $('#diYa').find('form[name="lawsuit_pledger_readonly"]').find('table').append(html1);
                $('#diYa').find('form[name="lawsuit_pledger_edit"]').find('table').find('tr:gt(0)').remove();
                $('#diYa').find('form[name="lawsuit_pledger_edit"]').find('table').append(html2);

                var step2_state = 2;
                if (lawsuitList.length>0) {
                    step2_state = 1;
                }
                $('#diYa').find('.step1_state').val(step1_state);
                $('#diYa').find('.step2_state').val(step2_state);
                $('#diYa').find('.step3_state').val(step3_state);
                $('#diYa').find('.step5_state').val(step5_state);
                $('#diYa').find('.step6_state').val(step6_state);
                $('#diYa').find('.step7_state').val(step7_state);

                if (step1_state == 2) {
                    $('#diYa').find('.step1_nothing').text('（暂无数据）');
                    $('#diYa').find('.step1_nothing').parent().parent().next().hide();
                }else if(step1_state == 1) {
                    $('#diYa').find('.step1_nothing').text('');
                    $('#diYa').find('.step1_nothing').parent().parent().next().show();
                }
                if (step2_state == 2) {
                    $('#diYa').find('.step2_nothing').text('（暂无数据）');
                    $('#diYa').find('.step2_nothing').parent().parent().next().hide();
                }else if(step2_state == 1) {
                    $('#diYa').find('.step2_nothing').text('');
                    $('#diYa').find('.step2_nothing').parent().parent().next().show();
                }
                if (step3_state == 2) {
                    $('#diYa').find('.step3_nothing').text('（暂无数据）');
                    $('#diYa').find('.step3_nothing').parent().parent().next().hide();
                } else if(step3_state == 1) {
                    $('#diYa').find('.step3_nothing').text('');
                    $('#diYa').find('.step3_nothing').parent().parent().next().show();
                }
                if (step5_state == 2) {
                    $('#diYa').find('.step5_nothing').text('（暂无数据）');
                    $('#diYa').find('.step5_nothing').parent().parent().next().hide();
                }else if(step5_state == 1) {
                    $('#diYa').find('.step5_nothing').text('');
                    $('#diYa').find('.step5_nothing').parent().parent().next().show();
                }
                if (step6_state == 2) {
                    $('#diYa').find('.step6_nothing').text('（暂无数据）');
                    $('#diYa').find('.step6_nothing').parent().parent().next().hide();
                } else if(step6_state == 1) {
                    $('#diYa').find('.step6_nothing').text('');
                    $('#diYa').find('.step6_nothing').parent().parent().next().show();
                }
                if (step7_state == 2) {
                    $('#diYa').find('.step7_nothing').text('（暂无数据）');
                    $('#diYa').find('.step7_nothing').parent().parent().next().hide();
                } else if(step7_state == 1) {
                    $('#diYa').find('.step7_nothing').text('');
                    $('#diYa').find('.step7_nothing').parent().parent().next().show();
                }

                $('.stakeholder_pledger_readonly7').find('.payment_reservation').removeAttr("readonly").val(model.payment_reservation).attr("readonly", "readonly");
                $('.stakeholder_pledger_readonly7').find('.reservation_evidence').text(model.reservation_evidence);
                $('.stakeholder_pledger_readonly7').find('.payment_radical').removeAttr("readonly").val(model.payment_radical).attr("readonly", "readonly");
                $('.stakeholder_pledger_readonly7').find('.radical_evidence').text(model.radical_evidence);

                break;
            case 3:
                obj1 = $('form[name="stakeholder_warrantor_readonly"]');
                obj2 = $('form[name="stakeholder_warrantor_edit"]');
                $('#stakeholder_warrantor_id').val(model.id);

                var html1 = get_lawsuit_readonly(lawsuitList);
                var html2 = get_lawsuit_edit(lawsuitList);
                $('#baoZheng').find('form[name="lawsuit_warrantor_readonly"]').find('table').find('tr:gt(0)').remove();
                $('#baoZheng').find('form[name="lawsuit_warrantor_readonly"]').find('table').append(html1);
                $('#baoZheng').find('form[name="lawsuit_warrantor_edit"]').find('table').find('tr:gt(0)').remove();
                $('#baoZheng').find('form[name="lawsuit_warrantor_edit"]').find('table').append(html2);

                var step2_state = 2;
                if (lawsuitList.length>0) {
                    step2_state = 1;
                }
                $('#baoZheng').find('.step1_state').val(step1_state);
                $('#baoZheng').find('.step2_state').val(step2_state);
                $('#baoZheng').find('.step3_state').val(step3_state);
                $('#baoZheng').find('.step5_state').val(step5_state);
                $('#baoZheng').find('.step6_state').val(step6_state);
                $('#baoZheng').find('.step7_state').val(step7_state);

                if (step1_state == 2) {
                    $('#baoZheng').find('.step1_nothing').text('（暂无数据）');
                    $('#baoZheng').find('.step1_nothing').parent().parent().next().hide();
                } else if(step1_state == 1) {
                    $('#baoZheng').find('.step1_nothing').text('');
                    $('#baoZheng').find('.step1_nothing').parent().parent().next().show();
                }
                if (step2_state == 2) {
                    $('#baoZheng').find('.step2_nothing').text('（暂无数据）');
                    $('#baoZheng').find('.step2_nothing').parent().parent().next().hide();
                } else if(step2_state == 1) {
                    $('#baoZheng').find('.step2_nothing').text('');
                    $('#baoZheng').find('.step2_nothing').parent().parent().next().show();
                }
                if (step3_state == 2) {
                    $('#baoZheng').find('.step3_nothing').text('（暂无数据）');
                    $('#baoZheng').find('.step3_nothing').parent().parent().next().hide();
                } else if(step3_state == 1) {
                    $('#baoZheng').find('.step3_nothing').text('');
                    $('#baoZheng').find('.step3_nothing').parent().parent().next().show();
                }
                if (step5_state == 2) {
                    $('#baoZheng').find('.step5_nothing').text('（暂无数据）');
                    $('#baoZheng').find('.step5_nothing').parent().parent().next().hide();
                } else if(step5_state == 1) {
                    $('#baoZheng').find('.step5_nothing').text('');
                    $('#baoZheng').find('.step5_nothing').parent().parent().next().show();
                }
                if (step6_state == 2) {
                    $('#baoZheng').find('.step6_nothing').text('（暂无数据）');
                    $('#baoZheng').find('.step6_nothing').parent().parent().next().hide();
                } else if(step6_state == 1) {
                    $('#baoZheng').find('.step6_nothing').text('');
                    $('#baoZheng').find('.step6_nothing').parent().parent().next().show();
                }
                if (step7_state == 2) {
                    $('#baoZheng').find('.step7_nothing').text('（暂无数据）');
                    $('#baoZheng').find('.step7_nothing').parent().parent().next().hide();
                } else if(step7_state == 1) {
                    $('#baoZheng').find('.step7_nothing').text('');
                    $('#baoZheng').find('.step7_nothing').parent().parent().next().show();
                }
                break;
            case 4:
                obj1 = $('form[name="stakeholder_other_readonly"]');
                obj2 = $('form[name="stakeholder_other_edit"]');
                $('#stakeholder_other_id').val(model.id);

                var html1 = get_lawsuit_readonly(lawsuitList);
                var html2 = get_lawsuit_edit(lawsuitList);
                $('#qiTa').find('form[name="lawsuit_other_readonly"]').find('table').find('tr:gt(0)').remove();
                $('#qiTa').find('form[name="lawsuit_other_readonly"]').find('table').append(html1);
                $('#qiTa').find('form[name="lawsuit_other_edit"]').find('table').find('tr:gt(0)').remove();
                $('#qiTa').find('form[name="lawsuit_other_edit"]').find('table').append(html2);

                var step2_state = 2;
                if (lawsuitList.length>0) {
                    step2_state = 1;
                }
                $('#qiTa').find('.step1_state').val(step1_state);
                $('#qiTa').find('.step2_state').val(step2_state);
                $('#qiTa').find('.step3_state').val(step3_state);
                $('#qiTa').find('.step5_state').val(step5_state);
                $('#qiTa').find('.step6_state').val(step6_state);
                $('#qiTa').find('.step7_state').val(step7_state);

                if (step1_state == 2) {
                    $('#qiTa').find('.step1_nothing').text('（暂无数据）');
                    $('#qiTa').find('.step1_nothing').parent().parent().next().hide();
                } else if(step1_state == 1) {
                    $('#qiTa').find('.step1_nothing').text('');
                    $('#qiTa').find('.step1_nothing').parent().parent().next().show();
                }
                if (step2_state == 2) {
                    $('#qiTa').find('.step2_nothing').text('（暂无数据）');
                    $('#qiTa').find('.step2_nothing').parent().parent().next().hide();
                } else if(step2_state == 1) {
                    $('#qiTa').find('.step2_nothing').text('');
                    $('#qiTa').find('.step2_nothing').parent().parent().next().show();
                }
                if (step3_state == 2) {
                    $('#qiTa').find('.step3_nothing').text('（暂无数据）');
                    $('#qiTa').find('.step3_nothing').parent().parent().next().hide();
                } else if(step3_state == 1) {
                    $('#qiTa').find('.step3_nothing').text('');
                    $('#qiTa').find('.step3_nothing').parent().parent().next().show();
                }
                if (step5_state == 2) {
                    $('#qiTa').find('.step5_nothing').text('（暂无数据）');
                    $('#qiTa').find('.step5_nothing').parent().parent().next().hide();
                } else if(step5_state == 1) {
                    $('#qiTa').find('.step5_nothing').text('');
                    $('#qiTa').find('.step5_nothing').parent().parent().next().show();
                }
                if (step6_state == 2) {
                    $('#qiTa').find('.step6_nothing').text('（暂无数据）');
                    $('#qiTa').find('.step6_nothing').parent().parent().next().hide();
                } else if(step6_state == 1) {
                    $('#qiTa').find('.step6_nothing').text('');
                    $('#qiTa').find('.step6_nothing').parent().parent().next().show();
                }
                if (step7_state == 2) {
                    $('#qiTa').find('.step7_nothing').text('（暂无数据）');
                    $('#qiTa').find('.step7_nothing').parent().parent().next().hide();
                } else if(step7_state == 1) {
                    $('#qiTa').find('.step7_nothing').text('');
                    $('#qiTa').find('.step7_nothing').parent().parent().next().show();
                }
                break;
        }


        //工商信息
        obj1.find('.stakeholder_title').removeAttr("readonly").val(model.stakeholder_title).attr("readonly", "readonly");
        obj1.find('.registered_capital').removeAttr("readonly").val(model.registered_capital).attr("readonly", "readonly");
        obj1.find('.registered_address').removeAttr("readonly").val(model.registered_address).attr("readonly", "readonly");
        obj1.find('.registered_address').text(model.registered_address);
        obj1.find('.legal_representative').removeAttr("readonly").val(model.legal_representative).attr("readonly", "readonly");
        obj1.find('.scope_of_business').removeAttr("readonly").val(model.scope_of_business).attr("readonly", "readonly");
        obj1.find('.proportion').removeAttr("readonly").val(model.proportion).attr("readonly", "readonly");
        obj1.find('.borrower').removeAttr("readonly").val(model.borrower).attr("readonly", "readonly");
        obj1.find('.buy_back').removeAttr("readonly").val(model.buy_back).attr("readonly", "readonly");
        obj1.find('.buy_back').text(model.buy_back);

        //列失信
        var faith = '',
            limit_high = '';
        if (model.faith == 1) {
            faith = '是';
        } else if(model.faith == 2) {
            faith = '否';
        }
        if (model.limit_high == 1) {
            limit_high = '是';
        } else if(model.limit_high == 2) {
            limit_high = '否';
        }

        obj1.find('.faith').removeAttr("readonly").val(faith).attr("readonly", "readonly");
        obj1.find('.limit_high').removeAttr("readonly").val(limit_high).attr("readonly", "readonly");
        obj1.find('.block_list').removeAttr("readonly").val(model.block_list).attr("readonly", "readonly");
        obj1.find('.block_list').text(model.block_list);
        obj1.find('.block_list-pre').removeAttr("readonly").text(model.block_list).attr("readonly", "readonly");
        obj1.find('.block_value').removeAttr("readonly").val(model.block_value).attr("readonly", "readonly");
        obj1.find('.block_value').text(model.block_value);

        //担保详情
        obj1.find('.guarantee_scope').removeAttr("readonly").val(model.guarantee_scope).attr("readonly", "readonly");
        obj1.find('.guarantee_scope').text(model.guarantee_scope);
        obj1.find('.guarantee').removeAttr("readonly").val(model.guarantee).attr("readonly", "readonly");
        obj1.find('.guarantee').text(model.guarantee);
        obj1.find('.seal_order').removeAttr("readonly").val(model.seal_order).attr("readonly", "readonly");
        obj1.find('.seal_order').text(model.seal_order);

        if (type == 2) {
            obj1.find('.mortgage_order').removeAttr("readonly").val(model.mortgage_order).attr("readonly", "readonly");
            obj1.find('.mortgage_order').text(model.mortgage_order);
        } else {
            obj1.find('.other_mortgage').removeAttr("readonly").val(model.other_mortgage).attr("readonly", "readonly");
            obj1.find('.other_mortgage').text(model.other_mortgage);
        }

        obj1.find('.evaluate_price').removeAttr("readonly").val(model.evaluate_price).attr("readonly", "readonly");
        obj1.find('.auction_price').removeAttr("readonly").val(model.auction_price).attr("readonly", "readonly");
        obj1.find('.market_price').removeAttr("readonly").val(model.market_price).attr("readonly", "readonly");
        obj1.find('.market_price').removeAttr("readonly").text(model.market_price).attr("readonly", "readonly");

        //现场状态
        obj1.find('.rent').removeAttr("readonly").val(model.rent).attr("readonly", "readonly");
        obj1.find('.rent').text(model.rent);
        obj1.find('.live').removeAttr("readonly").val(model.live).attr("readonly", "readonly");
        obj1.find('.live').text(model.live);
        obj1.find('.interview').removeAttr("readonly").val(model.interview).attr("readonly", "readonly");
        obj1.find('.interview').text(model.interview);

        //回现评估
        obj1.find('.payment_reservation').removeAttr("readonly").val(model.payment_reservation).attr("readonly", "readonly");
        obj1.find('.reservation_evidence').removeAttr("readonly").val(model.reservation_evidence).attr("readonly", "readonly");
        obj1.find('.reservation_evidence').text(model.reservation_evidence);
        obj1.find('.payment_radical').removeAttr("readonly").val(model.payment_radical).attr("readonly", "readonly");
        obj1.find('.radical_evidence').removeAttr("readonly").val(model.radical_evidence).attr("readonly", "readonly");
        obj1.find('.radical_evidence').text(model.radical_evidence);

        // $('.stakeholder_pledger_readonly7').find('.payment_reservation').removeAttr("readonly").val(model.payment_reservation).attr("readonly", "readonly");
        // $('.stakeholder_pledger_readonly7').find('.reservation_evidence').text(model.reservation_evidence);
        // $('.stakeholder_pledger_readonly7').find('.payment_radical').removeAttr("readonly").val(model.payment_radical).attr("readonly", "readonly");
        // $('.stakeholder_pledger_readonly7').find('.radical_evidence').text(model.radical_evidence);

        //编辑
        if (state == 2) {
            //工商信息
            obj2.find('.stakeholder_title').val(model.stakeholder_title);
            obj2.find('.registered_capital').val(model.registered_capital);
            obj2.find('.registered_address').val(model.registered_address);
            obj2.find('.registered_address').text(model.registered_address);
            obj2.find('.legal_representative').val(model.legal_representative);
            obj2.find('.scope_of_business').val(model.scope_of_business);
            //          obj2.find('.scope_of_business-pre').text(model.scope_of_business);
            obj2.find('.proportion').val(model.proportion);
            obj2.find('.borrower').val(model.borrower);
            obj2.find('.buy_back').val(model.buy_back);
            obj2.find('.buy_back').text(model.buy_back);


            //列失信
            if (model.faith == 1) {
                obj2.find('.labelRowline .faith_true').trigger('click');
            } else if(model.faith == 2) {
                obj2.find('.labelRowline .faith_false').trigger('click');
            } else {
                obj2.find('.labelRowline .faith_true').prev().addClass('noActive');
                obj2.find('.labelRowline .faith_false').prev().addClass('noActive');
            }

            if (model.limit_high == 1) {
                obj2.find('.labelRowline .limit_high_true').trigger('click');
                //obj2.find('input:radio[name="ProjectInvestigationStakeholder[limit_high]"]').eq(1).removeAttr("checked");
                //obj2.find('input:radio[name="ProjectInvestigationStakeholder[limit_high]"]').eq(0).attr("checked", 'checked');
            } else if(model.limit_high == 2) {
                obj2.find('.labelRowline .limit_high_false').trigger('click');
            } else {
                obj2.find('.labelRowline .limit_high_true').prev().addClass('noActive');
                obj2.find('.labelRowline .limit_high_false').prev().addClass('noActive');
            }

            obj2.find('.block_list').val(model.block_list);
            obj2.find('.block_list').text(model.block_list);
            obj2.find('.block_list-pre').text(model.block_list);
            obj2.find('.block_value').val(model.block_value);
            obj2.find('.block_value').text(model.block_value);

            //担保详情
            obj2.find('.guarantee_scope').val(model.guarantee_scope);
            obj2.find('.guarantee_scope').text(model.guarantee_scope);
            obj2.find('.guarantee').val(model.guarantee);
            obj2.find('.guarantee').text(model.guarantee);
            obj2.find('.seal_order').val(model.seal_order);
            obj2.find('.seal_order').text(model.seal_order);

            if (type == 2) {
                obj2.find('.mortgage_order').val(model.mortgage_order);
                obj2.find('.mortgage_order').text(model.mortgage_order);
            } else {
                obj2.find('.other_mortgage').val(model.other_mortgage);
                obj2.find('.other_mortgage').text(model.other_mortgage);
            }

            obj2.find('.evaluate_price').val(model.evaluate_price);
            obj2.find('.auction_price').val(model.auction_price);
            obj2.find('.market_price').val(model.market_price);
            obj2.find('.market_price').text(model.market_price);

            //现场状态
            obj2.find('.rent').val(model.rent);
            obj2.find('.rent').text(model.rent);
            obj2.find('.live').val(model.live);
            obj2.find('.live').text(model.live);
            obj2.find('.interview').val(model.interview);
            obj2.find('.interview').text(model.interview);

            //回现评估
            obj2.find('.payment_reservation').val(model.payment_reservation);
            obj2.find('.reservation_evidence').val(model.reservation_evidence);
            obj2.find('.reservation_evidence').text(model.reservation_evidence);
            obj2.find('.payment_radical').val(model.payment_radical);
        }

    } else {
        obj1 = $('form[name="stakeholder_borrower_readonly"]');
        //工商信息、列失信
        obj1.find('.stakeholder_title').removeAttr("readonly").val(model.stakeholder_title).attr("readonly", "readonly");
        obj1.find('.registered_capital').removeAttr("readonly").val(model.registered_capital).attr("readonly", "readonly");
        obj1.find('.registered_address').removeAttr("readonly").val(model.registered_address).attr("readonly", "readonly");
        obj1.find('.registered_address').removeAttr("readonly").text(model.registered_address).attr("readonly", "readonly");
        obj1.find('.legal_representative').removeAttr("readonly").val(model.legal_representative).attr("readonly", "readonly");
        obj1.find('.scope_of_business').removeAttr("readonly").val(model.scope_of_business).attr("readonly", "readonly");
        obj1.find('.scope_of_business-pre').removeAttr("readonly").text(model.scope_of_business).attr("readonly", "readonly");
        obj1.find('.proportion').removeAttr("readonly").val(model.proportion).attr("readonly", "readonly");
        obj1.find('.borrower').removeAttr("readonly").val(model.borrower).attr("readonly", "readonly");
        obj1.find('.buy_back').removeAttr("readonly").val(model.buy_back).attr("readonly", "readonly");
        obj1.find('.buy_back-pre').removeAttr("readonly").text(model.buy_back).attr("readonly", "readonly");

        //列失信
        var faith = '',
            limit_high = '';
        if (model.faith == 1) {
            faith = '是';
        } else if(model.faith == 2) {
            faith = '否';
        }
        if (model.limit_high == 1) {
            limit_high = '是';
        } else if(model.limit_high == 2) {
            limit_high = '否';
        }

        obj1.find('.faith').removeAttr("readonly").val(faith).attr("readonly", "readonly");
        obj1.find('.limit_high').removeAttr("readonly").val(limit_high).attr("readonly", "readonly");
        obj1.find('.block_list').removeAttr("readonly").val(model.block_list).attr("readonly", "readonly");
        obj1.find('.block_list').removeAttr("readonly").text(model.block_list).attr("readonly", "readonly");
        obj1.find('.block_list-pre').removeAttr("readonly").text(model.block_list).attr("readonly", "readonly");
        obj1.find('.block_value').removeAttr("readonly").val(model.block_value).attr("readonly", "readonly");
        obj1.find('.block_value').removeAttr("readonly").text(model.block_value).attr("readonly", "readonly");
        obj1.find('.block_value-pre').removeAttr("readonly").text(model.block_value).attr("readonly", "readonly");

        //其它补充
        obj1.find('.update_log').removeAttr("readonly").val(model.update_log).attr("readonly", "readonly");
        obj1.find('.update_log-pre').removeAttr("readonly").text(model.update_log).attr("readonly", "readonly");
        obj1.find('.other_guarantee').removeAttr("readonly").val(model.other_guarantee).attr("readonly", "readonly");
        obj1.find('.other_guarantee-pre').removeAttr("readonly").text(model.other_guarantee).attr("readonly", "readonly");
        obj1.find('.seal_order').removeAttr("readonly").val(model.seal_order).attr("readonly", "readonly");
        obj1.find('.seal_order-pre').removeAttr("readonly").text(model.seal_order).attr("readonly", "readonly");
        obj1.find('.other_mortgage').removeAttr("readonly").val(model.other_mortgage).attr("readonly", "readonly");
        obj1.find('.other_mortgage-pre').removeAttr("readonly").text(model.other_mortgage).attr("readonly", "readonly");

        //市场询价
        obj1.find('.evaluate_price').removeAttr("readonly").val(model.evaluate_price).attr("readonly", "readonly");
        obj1.find('.auction_price').removeAttr("readonly").val(model.auction_price).attr("readonly", "readonly");
        obj1.find('.identical_price').removeAttr("readonly").val(model.identical_price).attr("readonly", "readonly");
        obj1.find('.identical_price').removeAttr("readonly").text(model.identical_price).attr("readonly", "readonly");
        obj1.find('.recently_price').removeAttr("readonly").val(model.recently_price).attr("readonly", "readonly");
        obj1.find('.recently_price').removeAttr("readonly").text(model.recently_price).attr("readonly", "readonly");
        obj1.find('.buyer_price').removeAttr("readonly").val(model.buyer_price).attr("readonly", "readonly");
        obj1.find('.buyer_price').removeAttr("readonly").text(model.buyer_price).attr("readonly", "readonly");
        obj1.find('.rental_price').removeAttr("readonly").val(model.rental_price).attr("readonly", "readonly");
        obj1.find('.rental_price').removeAttr("readonly").text(model.rental_price).attr("readonly", "readonly");
        obj1.find('.tax_price').removeAttr("readonly").val(model.tax_price).attr("readonly", "readonly");
        obj1.find('.tax_price').removeAttr("readonly").text(model.tax_price).attr("readonly", "readonly");

        //现场状态
        obj1.find('.rent').removeAttr("readonly").val(model.rent).attr("readonly", "readonly");
        obj1.find('.rent').removeAttr("readonly").text(model.rent).attr("readonly", "readonly");
        obj1.find('.rent-pre').removeAttr("readonly").text(model.rent).attr("readonly", "readonly");
        obj1.find('.live').removeAttr("readonly").val(model.live).attr("readonly", "readonly");
        obj1.find('.live-pre').removeAttr("readonly").text(model.live).attr("readonly", "readonly");
        obj1.find('.interview').removeAttr("readonly").val(model.interview).attr("readonly", "readonly");
        obj1.find('.interview').removeAttr("readonly").text(model.interview).attr("readonly", "readonly");
        obj1.find('.interview-pre').removeAttr("readonly").text(model.interview).attr("readonly", "readonly");

        //回现评估
        obj1.find('.payment_reservation').removeAttr("readonly").val(model.payment_reservation).attr("readonly", "readonly");
        obj1.find('.payment_reservation-pre').removeAttr("readonly").text(model.payment_reservation).attr("readonly", "readonly");
        obj1.find('.reservation_evidence').removeAttr("readonly").val(model.reservation_evidence).attr("readonly", "readonly");
        obj1.find('.reservation_evidence-pre').removeAttr("readonly").text(model.reservation_evidence).attr("readonly", "readonly");
        obj1.find('.payment_radical').removeAttr("readonly").val(model.payment_radical).attr("readonly", "readonly");
        obj1.find('.payment_radical-pre').removeAttr("readonly").text(model.payment_radical).attr("readonly", "readonly");
        obj1.find('.radical_evidence').removeAttr("readonly").val(model.radical_evidence).attr("readonly", "readonly");
        obj1.find('.radical_evidence').removeAttr("readonly").text(model.radical_evidence).attr("readonly", "readonly");
        obj1.find('.radical_evidence-pre').removeAttr("readonly").text(model.radical_evidence).attr("readonly", "readonly");


        $('#jieKuan').find('.step3_state').val(step3_state);
        $('#jieKuan').find('.step4_state').val(step4_state);
        $('#jieKuan').find('.step5_state').val(step5_state1);
        $('#jieKuan').find('.step6_state').val(step6_state);
        $('#jieKuan').find('.step7_state').val(step7_state);
        $('#jieKuan').find('.step3_nothing').text('');
        $('#jieKuan').find('.step4_nothing').text('');
        $('#jieKuan').find('.step5_nothing').text('');
        $('#jieKuan').find('.step6_nothing').text('');
        $('#jieKuan').find('.step7_nothing').text('');

        if (step3_state == 2) {
            $('#jieKuan').find('.step3_nothing').text('（暂无数据）');
            $('#jieKuan').find('.step3_nothing').parent().parent().next().hide();
        } else if(step3_state == 1) {
            $('#jieKuan').find('.step3_nothing').text('');
            $('#jieKuan').find('.step3_nothing').parent().parent().next().show();
        }
        if (step4_state == 2) {
            $('#jieKuan').find('.step4_nothing').text('（暂无数据）');
            $('#jieKuan').find('.step4_nothing').parent().parent().next().hide();
        } else if(step4_state == 1) {
            $('#jieKuan').find('.step4_nothing').text('');
            $('#jieKuan').find('.step4_nothing').parent().parent().next().show();
        }
        if (step5_state1 == 2) {
            $('#jieKuan').find('.step5_nothing').text('（暂无数据）');
            $('#jieKuan').find('.step5_nothing').parent().parent().next().hide();
        } else if(step5_state1 == 1) {
            $('#jieKuan').find('.step5_nothing').text('');
            $('#jieKuan').find('.step5_nothing').parent().parent().next().show();
        }
        if (step6_state == 2) {
            $('#jieKuan').find('.step6_nothing').text('（暂无数据）');
            $('#jieKuan').find('.step6_nothing').parent().parent().next().hide();
        } else if(step6_state == 1) {
            $('#jieKuan').find('.step6_nothing').text('');
            $('#jieKuan').find('.step6_nothing').parent().parent().next().show();
        }
        if (step7_state == 2) {
            $('#jieKuan').find('.step7_nothing').text('（暂无数据）');
            $('#jieKuan').find('.step7_nothing').parent().parent().next().hide();
        } else if(step7_state == 1) {
            $('#jieKuan').find('.step7_nothing').text('');
            $('#jieKuan').find('.step7_nothing').parent().parent().next().show();
        }
    }
}

/**
 * 保存——债权基本情况
 * @param investigation_url 保存地址
 * @param param 传参
 * @param obj  点击对象
 */
function investigation(investigation_url, param, obj, step_type) {
    //alert(investigation_url + '?step_type=' + step_type); return;
    $.ajax({
        type: "POST",//类型 POST GET
        url: investigation_url + '?step_type=' + step_type,
        data: param,
        datatype: "json",// 返回数据的格式"xml", "html", "script", "json", "jsonp", "text".
        // 在请求之前调用的函数
        // beforeSend: function () {

        // },
        // 调用执行后调用的函数
        // complete: function (XMLHttpRequest, textStatus) {

        // },
        success: function (data) {
            if (data.code == 200) {
                layer.msg('保存成功');
                $('.project_edit_state').val(1);
                obj.parent().parent().hide().prev().show().prev().find('img').show();
                var model = data.data.res;
                setInvestigation(model);

                //是否暂无数据
                if (isVariable1Empty(model.lawsuit) && isVariable1Empty(model.execution) && isVariable1Empty(model.auction)) {
                    $('#zhaiQuan').find('.step2_nothing').text('（暂无数据）');
                    $('#zhaiQuan').find('.step2_nothing').parent().parent().next().hide();
                    $('#zhaiQuan').find('.step2_state').val(2);
                } else {
                    $('#zhaiQuan').find('.step2_nothing').text('');
                    $('#zhaiQuan').find('.step2_nothing').parent().parent().next().show();
                    $('#zhaiQuan').find('.step2_state').val(1);
                }

                if (isVariable1Empty(model.records_investigation) && isVariable1Empty(model.records_consistence) && isVariable1Empty(model.order_sent) &&
                    isVariable1Empty(model.court_summons) && isVariable1Empty(model.execution_method) && isVariable1Empty(model.layer_interview)) {
                    $('#zhaiQuan').find('.step3_nothing').text('（暂无数据）');
                    $('#zhaiQuan').find('.step3_nothing').parent().parent().next().hide();
                    $('#zhaiQuan').find('.step3_state').val(2);
                } else {
                    $('#zhaiQuan').find('.step3_nothing').text('');
                    $('#zhaiQuan').find('.step3_nothing').parent().parent().next().show();
                    $('#zhaiQuan').find('.step3_state').val(1);
                }

                if (isVariable1Empty(model.debt_collection) && isVariable1Empty(model.prescription) && isVariable1Empty(model.origin_files)) {
                    $('#zhaiQuan').find('.step4_nothing').text('（暂无数据）');
                    $('#zhaiQuan').find('.step4_nothing').parent().parent().next().hide();
                    $('#zhaiQuan').find('.step4_state').val(2);
                } else {
                    $('#zhaiQuan').find('.step4_nothing').text('');
                    $('#zhaiQuan').find('.step4_nothing').parent().parent().next().show();
                    $('#zhaiQuan').find('.step4_state').val(1);
                }

                if (isVariable1Empty(model.conclusion)) {
                    $('#zongJie').find('.step10_nothing').text('（暂无数据）');
                    $('#zongJie').find('.step10_nothing').parent().parent().parent().next().hide();
                    $('#zongJie').find('.step10_state').val(2);
                } else {
                    $('#zongJie').find('.step10_nothing').text('');
                    $('#zongJie').find('.step10_nothing').parent().parent().parent().next().show();
                    $('#zongJie').find('.step10_state').val(1);
                }

            } else if (data.code == 400) {
                layer.msg(data.message);
            }
        },
        //调用出错执行的函数
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.msg('系统错误');
        }
    });
}

function cancel_investigation(url, param, obj) {
    $.ajax({
        type: "POST",//类型 POST GET
        url: url,
        data: param,
        datatype: "json",// 返回数据的格式"xml", "html", "script", "json", "jsonp", "text".
        success: function (data) {
            if (data.code == 200) {
                layer.msg('取消成功');
                $('.project_edit_state').val(1);
                obj.parent().parent().hide().prev().show().prev().find('img').show();

                var model = data.data.res;
                setInvestigation(model);

                var step2_state = $('#zhaiQuan').find('.step2_state').val(),
                    step3_state = $('#zhaiQuan').find('.step3_state').val(),
                    step4_state = $('#zhaiQuan').find('.step4_state').val(),
                    step10_state = $('#zongJie').find('.step10_state').val();

                if (step2_state == 1) {
                    $('#zhaiQuan').find('.step2_nothing').text('');
                    $('#zhaiQuan').find('.step2_nothing').parent().parent().next().show();
                } else if (step2_state == 2) {
                    $('#zhaiQuan').find('.step2_nothing').text('（暂无数据）');
                    $('#zhaiQuan').find('.step2_nothing').parent().parent().next().hide();
                }

                if (step3_state == 1) {
                    $('#zhaiQuan').find('.step3_nothing').text('');
                    $('#zhaiQuan').find('.step3_nothing').parent().parent().next().show();
                } else if (step3_state == 2) {
                    $('#zhaiQuan').find('.step3_nothing').text('（暂无数据）');
                    $('#zhaiQuan').find('.step3_nothing').parent().parent().next().hide();
                }

                if (step4_state == 1) {
                    $('#zhaiQuan').find('.step4_nothing').text('');
                    $('#zhaiQuan').find('.step4_nothing').parent().parent().next().show();
                } else if (step4_state == 2) {
                    $('#zhaiQuan').find('.step4_nothing').text('（暂无数据）');
                    $('#zhaiQuan').find('.step4_nothing').parent().parent().next().hide();
                }

                if (step10_state == 2) {
                    $('#zongJie').find('.step10_nothing').text('（暂无数据）');
                    $('#zongJie').find('.step10_nothing').parent().parent().parent().next().hide();
                } else if(step10_state == 1) {
                    $('#zongJie').find('.step10_nothing').text('');
                    $('#zongJie').find('.step10_nothing').parent().parent().parent().next().show();
                }
            } else if (data.code == 400) {
                layer.msg(data.message);
            }
        },
        //调用出错执行的函数
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.msg('系统错误');
        }
    });
}

function setInvestigation(model) {
    //债权基本情况
    $('#zhaiQuan').find('.borrower').val(model.borrower);
    $('#zhaiQuan').find('.guarantor').val(model.guarantor);
    $('#zhaiQuan').find('.mortgagor').val(model.mortgagor);

    //抵压物类型
    var InvestigationMortgageType = ['', '房产', '土地', '林矿', '交通运输', '机械设备', '股权', '无形资产', '其他资产'],
        mortgage_type_arr = model.mortgage_type.split(','),
        mortgage = [];
    for (var i = 0; i < mortgage_type_arr.length; i++) {
        mortgage.push(InvestigationMortgageType[mortgage_type_arr[i]]);
    }
    $('#zhaiQuan').find('.mortgage_type').val(mortgage.join('、'));
    $('#zhaiQuan').find('.principal').val(model.principal);
    $('#zhaiQuan').find('.interest').val(model.interest);

    //司法进展
    // $('#zhaiQuan').find('.lawsuit').val(model.lawsuit);
    // $('#zhaiQuan').find('.execution').val(model.execution);
    // $('#zhaiQuan').find('.auction').val(model.auction);
    $('#zhaiQuan').find('.lawsuit-pre').text(model.lawsuit);
    $('#zhaiQuan').find('.execution-pre').text(model.execution);
    $('#zhaiQuan').find('.auction-pre').text(model.auction);

    //本案诉讼情况
    // $('#zhaiQuan').find('.records_investigation').val(model.records_investigation);
    // $('#zhaiQuan').find('.records_consistence').val(model.records_consistence);
    // $('#zhaiQuan').find('.order_sent').val(model.order_sent);
    // $('#zhaiQuan').find('.court_summons').val(model.court_summons);
    // $('#zhaiQuan').find('.execution_method').val(model.execution_method);
    // $('#zhaiQuan').find('.layer_interview').val(model.layer_interview);
    $('#zhaiQuan').find('.records_investigation-pre').text(model.records_investigation);
    $('#zhaiQuan').find('.records_consistence').val(model.records_consistence);
    $('#zhaiQuan').find('.records_consistence').text(model.records_consistence);
    $('#zhaiQuan').find('.order_sent').val(model.order_sent);
    $('#zhaiQuan').find('.order_sent').text(model.order_sent);
    $('#zhaiQuan').find('.court_summons').val(model.court_summons);
    $('#zhaiQuan').find('.court_summons').text(model.court_summons);
    $('#zhaiQuan').find('.execution_method-pre').text(model.execution_method);
    $('#zhaiQuan').find('.layer_interview-pre').text(model.layer_interview);

    //未诉时效
    // $('#zhaiQuan').find('.debt_collection').val(model.debt_collection);
    // $('#zhaiQuan').find('.prescription').val(model.prescription);
    // $('#zhaiQuan').find('.origin_files').val(model.origin_files);
    $('#zhaiQuan').find('.debt_collection-pre').text(model.debt_collection);
    $('#zhaiQuan').find('.prescription-pre').text(model.prescription);
    $('#zhaiQuan').find('.origin_files-pre').text(model.origin_files);

    //尽调评估总结
    $('#zongJie').find('.conclusion').val(model.conclusion);
    $('#zongJie').find('.conclusion').text(model.conclusion);

    $('#zhaiQuan').find('#investigation_id1').val(model.id);
    $('#zhaiQuan').find('#investigation_id2').val(model.id);
    $('#zhaiQuan').find('#investigation_id3').val(model.id);
    $('#zhaiQuan').find('#investigation_id4').val(model.id);
}


function isVariable1Empty(variable1) {
    if (variable1 === null || variable1 === '' || variable1 === undefined) {
        return true
    } else {
        return false;
    }
}

